/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.sequence.ui.properties.tabbed;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.uml2.uml.Message;

import com.cea.papyrus.diagram.sequence.ui.composites.MessageArgumentComposite;
import com.cea.papyrus.umlutils.Element;

/**
 * Defines use cases section of classifiers.
 * 
 */
public class MessageArgumentSection extends PropertyViewSection {
	
	/**
	 * The use cases composite.
	 */
	private MessageArgumentComposite argumentComposite;
		
	/**
	 * Creates the controls.
	 * 
	 * @param tabbedPropertySheetPage the tabbed property sheet page
	 * @param parent the parent
	 */
	@Override
	public void createControls(Composite parent,
            TabbedPropertySheetPage tabbedPropertySheetPage) {
        super.createControls(parent, tabbedPropertySheetPage);

        parent.setLayout(new FormLayout());
		FormData data;
		
		data = new FormData();
		data.right = new FormAttachment(100, 0);
		data.left = new FormAttachment(0, 0);
		
		// table for Parameters
		argumentComposite = new MessageArgumentComposite();
		argumentComposite.createContent(parent, tabbedPropertySheetPage.getWidgetFactory());
		argumentComposite.setLayoutData(data);
    }
    
	/**
	 * Refresh.
	 */
	@Override
	public void refresh() {
		argumentComposite.refresh();
    }

	/**
	 * Sets the input.
	 * 
	 * @param part the part
	 * @param selection the selection
	 */
	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
        super.setInput(part, selection); 
    	if(umlElement instanceof Message) {
    		Message message = (Message) umlElement;
    		argumentComposite.setElement(new Element(message));
    		argumentComposite.setContentProvider(modelManager);
    		argumentComposite.setLabelProvider(modelManager);
    	}       
    }
	
	
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.core.ui.properties.tabbed.PropertyViewSection#dispose()
	 */
	/**
	 * 
	 */
	public void dispose(){
		super.dispose();
		if(argumentComposite!=null)
			argumentComposite.dispose();
	}
}